 package com.xinlin.common.utils;

import com.xinlin.common.utils.ip.IpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

 /**
  * <p>
  *  打印项目信息
  * </p>
  * @author geekidea
  * @date 2019-05-08
  **/
 @Slf4j
 public class PrintApplicationInfo {


     /**
      * 执行之前，打印前置条件提示
      */
     public static void printTip(){
         StringBuffer tip = new StringBuffer();
         tip.append("======================================================================================\n");
         tip.append("                                                                                  \n");
         tip.append("                               !!!准备工作!!!                                      \n");
         tip.append(" 1.请先在MySQL中创建数据库，默认数据库名称为：                        \n");
         tip.append(" 2.数据库脚本在项目                                        \n");
         tip.append(" 3.请先启动redis服务                                                                \n");
         tip.append(" 4.更多注意事项：                                                                                  \n");
         tip.append("                                                                                  \n");
         tip.append("======================================================================================\n");
         log.info("\n{}", tip.toString());
     }

     /**
      * 启动成功之后，打印项目信息
      */
     public static void print(ConfigurableApplicationContext context){
         ConfigurableEnvironment environment = context.getEnvironment();
         // 项目名称
         String projectFinalName = environment.getProperty("xinlin.name");
         // 项目版本
         String projectVersion = environment.getProperty("xinlin.version");
         // 项目profile
         String profileActive = environment.getProperty("spring.profiles.active");
         // 项目路径
         String contextPath = environment.getProperty("server.servlet.context-path");
         // 项目端口
         String port = environment.getProperty("server.port");

         String proName = environment.getProperty("pro.name");


         String homeUrl = "http://" + IpUtils.getLocalhostIp() + ":" + port + contextPath;
         StringBuffer tip = new StringBuffer();
         tip.append("(♥◠‿◠)ﾉﾞ  启动成功   ლ(´ڡ`ლ)ﾞ  \n ");
         tip.append("projectName : "+projectFinalName + " \n");
         tip.append("projectVersion : "+projectVersion + " \n");
         tip.append("profileActive : "+profileActive + " \n" );
         tip.append("contextPath : " + contextPath + " \n" );
         tip.append("url : " + homeUrl + " \n" );
         tip.append("yml name ：" + proName + " \n" );

         log.info("\n{}", tip.toString());
     }

 }
